package com.source.module_kotlin_library.widget

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import android.util.Log
import android.view.View
import com.source.module_kotlin_library.R

class CircleView : View {
    private val TAG = this.javaClass.simpleName
    private var paint = Paint()
    var PADDING = 100f
    var RADIUS = 100f

    constructor(context: Context?) : this(context, null)
    constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

    init {
        paint.isAntiAlias = true
        paint.color = resources.getColor(R.color.black)
    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        var size = (PADDING + RADIUS).toInt()
        size *= 2

        var width = resolveSize(size, widthMeasureSpec)
        var height = resolveSize(size, heightMeasureSpec)

        setMeasuredDimension(width, height)
    }

    override fun onDraw(canvas: Canvas) {
        canvas.drawCircle(PADDING + RADIUS, PADDING + RADIUS, RADIUS, paint)
    }
}